package com.hf.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.hf.entity.Order;
import com.hf.utils.DBUtils;



public class OrderDao {
	
	

	public List<Order> selectOder(int user_id){
		
		Connection con= null;
		
		PreparedStatement ps= null;
		List<Order> list = new ArrayList<Order>();
		ResultSet re =null;
		
		
		String sql= "select * from Order1 where user_id=?";
		
	
		try {
			
			con=DBUtils.getConnection();
			ps= con.prepareStatement(sql);
			ps.setInt(1,user_id);
			re= ps.executeQuery();
			Order order= null;
			while(re.next()){
				order= new Order();
				order.setOrder_id(re.getInt("order_id"));
				order.setOrder_num(re.getString("order_num"));
				order.setOrder_time(re.getDate("order_time"));
				order.setUesr_id(re.getInt("user_id"));
				order.setOnt1(re.getInt("ont1"));
				order.setAlready(re.getInt("already"));
				order.setWait(re.getInt("wait"));
				order.setEvaluate(re.getInt("evaluate"));
				list.add(order);
				
				
			}
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.close(con, re, null, ps);
			
			
		}	
		return list;		
	}
	
	//������
	public int ontContent(){

		Connection con= null;
		
		PreparedStatement ps= null;
		
		ResultSet re =null;
		 int flag=0;
		String sql= "select * from Order1 where ont1=?";
		try {
			con=DBUtils.getConnection();
			ps= con.prepareStatement(sql);
			ps.setInt(1, 1);
			re=ps.executeQuery();
			while(re.next()){
				flag++;			
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.close(con, re,null , ps);
			
		}
		
		return flag;

	}
	
	//���������
	public int AlreadyContent(){

		Connection con= null;
		
		PreparedStatement ps= null;
		
		ResultSet re =null;
		 int flag=0;
		String sql= "select * from Order1 where already=?";
		try {
			con=DBUtils.getConnection();
			ps= con.prepareStatement(sql);
			ps.setInt(1,1);
			re=ps.executeQuery();
			while(re.next()){
				flag++;			
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.close(con, re,null , ps);
			
		}
		
		return flag;

	}
	
	//���ջ�������
	public int waitContent(){

		Connection con= null;
		
		PreparedStatement ps= null;
		
		ResultSet re =null;
		 int flag=0;
		String sql= "select * from Order1 where wait=?";
		try {
			con=DBUtils.getConnection();
			ps= con.prepareStatement(sql);
			ps.setInt(1,1);
			re=ps.executeQuery();
			while(re.next()){
				flag++;			
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.close(con, re,null , ps);
			
		}
		
		return flag;

	}
	
	//�����۶�����
	public int evaluateContent(){

		Connection con= null;
		
		PreparedStatement ps= null;
		
		ResultSet re =null;
		 int flag=0;
		String sql= "select * from Order1 where evaluate=?";
		try {
			con=DBUtils.getConnection();
			ps= con.prepareStatement(sql);
			ps.setInt(1,1);
			re=ps.executeQuery();
			while(re.next()){
				flag++;			
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.close(con, re,null , ps);
			
		}
		
		return flag;

	}
	
    

}
